import 'package:audioplayers/audioplayers.dart';
import 'package:client/provider/app_provider.dart';
import 'package:flutter/material.dart';

class Fun {
  static AudioPlayer player = AudioPlayer();

  static Future<void> sound() async {
    // await player.setSourceAsset("tip.mp3");
    // player.resume();
    await player.play(AssetSource("tip.mp3"));
  }

  // static sound() {
  //   player.resume();
  // }

  static buildTalkId(List<String> arr) {
    var len = arr.length;
    var talkId = "";
    if (len == 0) {
      talkId = "";
    } else if (len == 1) {
      talkId = arr[0];
    } else {
      arr.sort();
      talkId = arr.join("_");
    }
    return talkId;
  }

  static Future<void> dialog(String title, String content) {
    return showDialog<void>(
      context: AppProvider.getContext(),
      barrierDismissible: true, // user must tap button!
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text(title),
          content: Text(content),
          actions: <Widget>[
            TextButton(
              child: const Text('确定'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }
}
